class TeacherEvaluateController {

    def authenticateService
    static allowedMethods = [save: "POST", update: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        def teacherEvaluateInstanceList = TeacherEvaluate.findAllByTeacher(Teacher.get(params.id))
        [teacherEvaluateInstanceList: teacherEvaluateInstanceList, teacherEvaluateInstanceTotal: teacherEvaluateInstanceList.count()]
    }

    def create = {
        def teacherEvaluateInstance = new TeacherEvaluate()
        teacherEvaluateInstance.properties = params
        return [teacherEvaluateInstance: teacherEvaluateInstance,teacherID:params.id]
    }

    def save = {
        def flag = params.evaluateFlag?params.evaluateFlag:''
        def teacherEvaluateInstance = new TeacherEvaluate(params)
        teacherEvaluateInstance.teacher = Teacher.get(params.teacherID);
//        studentEvaluateInstance.postTeacher = Teacher.get(authenticateService.userDomain().id);
        teacherEvaluateInstance.postTeacher = authenticateService.userDomain()
        if (teacherEvaluateInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), teacherEvaluateInstance])}"
            redirect(action: "list",id:params.teacherID,params:[evaluateFlag:flag])
        }
        else {
            render(view: "create", model: [teacherEvaluateInstance: teacherEvaluateInstance,id:params.teacherID,evaluateFlag:flag])
        }
    }

    def show = {
        def flag = params.evaluateFlag?params.evaluateFlag:''
        def teacherEvaluateInstance = TeacherEvaluate.get(params.id)
        if (!teacherEvaluateInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
            redirect(action: "list",params:[evaluateFlag:flag])
        }
        else {
            render(view: "show", model: [teacherEvaluateInstance: teacherEvaluateInstance,teacherID:teacherEvaluateInstance.teacher.id])
            
        }
    }

    def edit = {
        def flag = params.evaluateFlag?params.evaluateFlag:''
        def teacherEvaluateInstance = TeacherEvaluate.get(params.id)
        if (!teacherEvaluateInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
            redirect(action: "list",params:[evaluateFlag:flag])
        }
        else {
            return [teacherEvaluateInstance: teacherEvaluateInstance,teacherID:teacherEvaluateInstance.teacher.id]
        }
    }

    def update = {
        def teacherEvaluateInstance = TeacherEvaluate.get(params.id)
        def flag = params.evaluateFlag?params.evaluateFlag:''
        if (teacherEvaluateInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (teacherEvaluateInstance.version > version) {
                    
                    teacherEvaluateInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate')] as Object[], "Another user has updated this TeacherEvaluate while you were editing")
                    render(view: "edit", model: [teacherEvaluateInstance: teacherEvaluateInstance,evaluateFlag:flag])
                    return
                }
            }
            teacherEvaluateInstance.properties = params
            if (!teacherEvaluateInstance.hasErrors() && teacherEvaluateInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), teacherEvaluateInstance])}"
                redirect(action: "list",id:teacherEvaluateInstance.teacher.id,params:[evaluateFlag:flag])
            }
            else {
                render(view: "edit", model: [teacherEvaluateInstance: teacherEvaluateInstance,evaluateFlag:flag])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
            redirect(action: "list",params:[evaluateFlag:flag])
        }
    }

    def delete = {
        def flag = params.evaluateFlag?params.evaluateFlag:''
        def teacherEvaluateInstance = TeacherEvaluate.get(params.id)
        if (teacherEvaluateInstance) {
            try {
                teacherEvaluateInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
                redirect(action: "list", id: params.teacherID,params:[evaluateFlag:flag])
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
                redirect(action: "list", id: params.id,params:[teacherID:params.teacherID,evaluateFlag:flag])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'teacherEvaluate.label', default: 'TeacherEvaluate'), params.id])}"
            redirect(action: "list", id: params.id,params:[teacherID:params.teacherID,evaluateFlag:flag])
        }
    }
}
